package com.huanletao.quartz.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * description: QuartzConfig <br>
 * date: 2022/7/4 12:26 <br>
 * author: 踏雪无痕 <br>
 * version: 1.0 <br>
 */
@Configuration
@ComponentScan("com.huanletao.quartz")
public class QuartzConfig {

    @Bean
    public DruidDataSource druidDataSource() {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("root");
        druidDataSource.setUrl("jdbc:mysql:///flowable");
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        return druidDataSource;
    }

//    @Bean(name = "scheduledExecutorService")
//    protected ScheduledExecutorService scheduledExecutorService() {
//        return new ScheduledThreadPoolExecutor(2,
//                new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
//                new ThreadPoolExecutor.CallerRunsPolicy());
//    }

    /**
     *
     * @param dataSource
     * @return
     */

    @Bean
    public QuartzScheduleFactoryBean quartzScheduleFactoryBean(DataSource dataSource) throws Exception {
        QuartzScheduleFactoryBean scheduleFactoryBean = new QuartzScheduleFactoryBean();
        scheduleFactoryBean.setDataSource(dataSource);
        return scheduleFactoryBean;
    }
}
